package didi.hcp.questionrobot.controller;

import didi.hcp.questionrobot.bo.CategoryBO;
import didi.hcp.questionrobot.common.CommonResponse;
import didi.hcp.questionrobot.entity.Category;
import didi.hcp.questionrobot.service.ICategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Controller
 *
 * @author huchengpeng
 * @date 2021-12-11 16:42:08
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/category/")
public class CategoryController extends BaseController {
    @Autowired
    private ICategoryService categoryService;

    @GetMapping("list")
    public CommonResponse list() {
        final List<Category> list = categoryService.list();
        return CommonResponse.SUCCESS().data(list);
    }

    @PostMapping("addCategory")
    public CommonResponse addCategory(CategoryBO categoryBO) {
        final boolean success = categoryService.addCategory(categoryBO);
        return success ? CommonResponse.SUCCESS() : CommonResponse.FAIL();
    }

    @PutMapping("updateCategory")
    public CommonResponse updateCategory(CategoryBO categoryBO) {
        final boolean success = categoryService.updateCategory(categoryBO);
        return success ? CommonResponse.SUCCESS() : CommonResponse.FAIL();
    }

}
